package com.demo.pojo;

import lombok.Data;

/**
 * 整个项目中用于统一返回响应结果的处理类
 */
@Data
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(2000);
        result.setMessage("操作成功");
        result.setData(data);
        return result;
    }
    public static <T> Result<T> success(T data , String message){
        Result<T> result = new Result<>();
        result.setCode(2000);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
    public static <T> Result<T> fail(String message){
        Result<T> result = new Result<>();
        result.setCode(5000);
        result.setMessage(message);
        result.setData(null);
        return result;
    }
    public static <T> Result<T> fail(T data ,String message){
        Result<T> result = new Result<>();
        result.setCode(5000);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
}
